//
//  GPBaseViewController.m
//  gupiao
//
//  Created by mac on 2019/8/14.
//  Copyright © 2019 mac. All rights reserved.
//

#import "GPBaseViewController_NN.h"

@interface GPBaseViewController_NN ()
@property (nonatomic,strong) MBProgressHUD *HUD;
@property (nonatomic,assign) BOOL isShowHUD;
@end

@implementation GPBaseViewController_NN

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initNavBack];
    [self setUp];
}

-(void)backAction{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)initNavBack{
    if (_navTitle) {
        self.navigationItem.title = _navTitle;
    }
    
    if (self.navigationController.childViewControllers.count>1) {
        UIImage *backImage = [[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithImage:backImage style:UIBarButtonItemStylePlain target:self action:@selector(backAction)];
        self.navigationItem.leftBarButtonItem = back;
    }
}

-(void)alertWithTitle:(NSString *)title WithMessage:(NSString *)message WithActions:(NSArray *)actions{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    for (UIAlertAction *action in actions) {
        [alert addAction:action];
    }
    [self presentViewController:alert animated:YES completion:nil];
}

- (void)showLoadingAnimatedToView:(UIView *)view{
    if (_isShowHUD) {
        return;
    }
    if (view == nil) view = [UIApplication sharedApplication].keyWindow;
    
    _HUD = [MBProgressHUD showHUDAddedTo:view animated:YES];
    
    _HUD.mode = MBProgressHUDModeIndeterminate;
    
    _HUD.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    
    _HUD.bezelView.color = [[UIColor blackColor] colorWithAlphaComponent:0.7];
    
    _HUD.contentColor = [UIColor whiteColor];
    
    _HUD.square = YES;
    
    _isShowHUD = YES;
}

- (void)showLoadingAnimatedToView:(UIView *)view WithTitle:(NSString*)title{
    if (_isShowHUD) {
        return;
    }
    if (view == nil) view = [UIApplication sharedApplication].keyWindow;
    
    _HUD = [MBProgressHUD showHUDAddedTo:view animated:YES];
    
    _HUD.label.text = title;
    
    _HUD.mode = MBProgressHUDModeIndeterminate;
    
    _HUD.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    
    _HUD.bezelView.color = [[UIColor blackColor] colorWithAlphaComponent:0.7];
    
    _HUD.contentColor = [UIColor whiteColor];
    
    _HUD.square = YES;
    
    _isShowHUD = YES;
}

- (void)dismissLoadingAnimatedToView{
    [_HUD hideAnimated:YES afterDelay:0.25];
    _isShowHUD = NO;
}

-(void)setUp{
    
}

-(UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
